package com.cl.pile.rule.filter;

import org.ahocorasick.trie.Trie;

/**
 * @author chenyitao
 * @date 2021/3/12
 */
public class InContainsAndOperation  extends BaseContentOperation implements IFilterOperation {
    @Override
    public boolean filterMatch(Object value, String matchValue) {
        if (value == null || matchValue == null) {
            return false;
        }

        int matchSize = 0;
        String[] matchValues = matchValue.split(",");
        if (matchValues.length > 10) {
            Trie trie = Trie.builder()
                    .addKeywords(matchValues)
                    .build();
            matchSize = trie.parseText(String.valueOf(value)).size();
        } else {
            for (String val : matchValues) {
                if (replaceSpace(String.valueOf(value)).contains(val)) {
                    matchSize++;
                }
            }
        }
        return matchSize == matchValues.length;
    }

    @Override
    public String filterName() {
        return "列表包含（且）";
    }
}
